# 开始场景
import sys

import pygame
import os

from shared_variables import SCREEN, WHITE, CONFIG, BLACK, FONT
from scenes.base_scene import Scene


class GameOverScene(Scene):
    def __init__(self, screen: pygame.surface.Surface):
        super().__init__()
        self.screen = screen
        self.background = pygame.image.load(CONFIG['assets']['background']['lose'])  # 加载背景图片
        self.font = pygame.font.SysFont("方正粗黑宋简体", 48)
        self.text = self.font.render("破产了，点击任意键离开游戏", True, BLACK)
        self.text_rect = self.text.get_rect(center=(CONFIG['screen']['width'] // 2, CONFIG['screen']['width'] // 2))
        # 计算蒙层的大小和位置
        self.overlay_rect = self.text_rect.inflate(20, 20)  # 给文字周围留出一些空间
        self.overlay = pygame.Surface((self.overlay_rect.width, self.overlay_rect.height), pygame.SRCALPHA)
        self.overlay.fill((255, 255, 255, 128))  # 白色半透明

    def handle_events(self, event):
        if event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.KEYDOWN:
            pygame.quit()
            sys.exit()
        return None

    def draw(self):
        self.screen.blit(self.background, (0, 0))  # 绘制背景图片

        # 绘制蒙层到屏幕
        self.screen.blit(self.overlay, self.overlay_rect.topleft)

        # 绘制文字
        self.screen.blit(self.text, self.text_rect)
